﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Scrum.SwimLanes.Models;
using System.Configuration;
using System.Web.Hosting;


namespace Scrum.SwimLanes.Controllers
{
    public class HomeController : Controller
    {
        public IWorkItemRepository Repository { get; set; }

        public HomeController()
            : this(new WorkItemRepository())
        {

        }
        public HomeController(IWorkItemRepository repository)
        {
            this.Repository = repository;
        }

        public ActionResult Index()
        {
            return View();
        }

        public ActionResult TeamProject(string tp, int? sNo, string iType)
        {
            ViewData["SprintNumber"] = sNo;
            ViewData["TeamProjectName"] = tp;
            if (iType.Equals("Sprint"))
            { 
                return View("SprintBacklogView");
            }
            return View("ProductBacklogView");
        }

        [AcceptVerbs(HttpVerbs.Get)]
        public JsonResult GetSprintBacklogItems(int sNo, string tp)
        {
            var clientWorkItemList = Repository.GetWorkItems(sNo, tp, WorkItemType.SprintBacklogItem);
            return this.Json(clientWorkItemList, JsonRequestBehavior.AllowGet);
        }

        [AcceptVerbs(HttpVerbs.Get)]
        public JsonResult GetProductBacklogItems(int sNo, string tp)
        {
            var clientWorkItemList = Repository.GetWorkItems(sNo, tp, WorkItemType.ProductBacklogItem);
            return this.Json(clientWorkItemList, JsonRequestBehavior.AllowGet);
        }      

        public JsonResult ChangeStatus(string tp, int sNo, int wId, string nStatus)
        {
            if (Repository.ChangeStatus(tp, sNo, wId, nStatus))
            {
                return Json(true);
            }
            return Json(false);
        }

        public ActionResult About()
        {
            return View();
        }

          
    }
}
